import { ArticleNormalCategory, CarouselPositionCode, EvaluationCategory } from "common/utils/data";
import {List } from "antd";
import { articleV1ControllerIndexNormal } from '@/services/auto/article';
import ScrollPageList from "@/components/ScrollPageList";
import Item from "./Item";
import AdBanner from "@/components/AdBanner";

const bannerMap: Record<ArticleNormalCategory, [CarouselPositionCode, CarouselPositionCode]> = {
  [ArticleNormalCategory.NEWS]: [CarouselPositionCode.NEWS_LIST_TOP_LEFT, CarouselPositionCode.NEWS_LIST_TOP_RIGHT],
  [ArticleNormalCategory.POINT]: [CarouselPositionCode.POINT_LIST_TOP_LEFT, CarouselPositionCode.POINT_LIST_TOP_RIGHT],
  [ArticleNormalCategory.REVIEW]: [CarouselPositionCode.REVIEW_LIST_TOP_LEFT, CarouselPositionCode.REVIEW_LIST_TOP_RIGHT],
  [ArticleNormalCategory.HIFI_DISCUSS]: [CarouselPositionCode.HIFI_DISCUSS_LIST_TOP_LEFT, CarouselPositionCode.HIFI_DISCUSS_LIST_TOP_RIGHT],
};

export default function NormalArticleList({category, keyword}:{category: ArticleNormalCategory, keyword?: string}){
  return <>
    <div className="flex gap-[16px]">
      {bannerMap[category].map(item=>{
        return <AdBanner key={item} wrapClassName="mb-[16px] flex-1 min-w-0" positionCode={item} width="658px" height="100px" ossFormatParam="?x-oss-process=image/resize,w_658,h_100" />
      })}
    </div>
    <ScrollPageList param={{category, keyword}} service={articleV1ControllerIndexNormal} order={{
      orderBy: 'publishTime',
      direction: 'DESC',
    }}>
      {(data)=>{
        return <List
          itemLayout="vertical"
          size="large"
          dataSource={data}
          rowKey="uuid"
          renderItem={(item) => {
            return <Item item={item} />
          }}
        />
      }}
    </ScrollPageList>
  </>
}
